package logic

import (
	"api/model/mysql"
	"context"
	"house_srv/house"
	"house_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddGoodsLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddGoodsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddGoodsLogic {
	return &AddGoodsLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AddGoodsLogic) AddGoods(in *house.AddGoodsRequest) (*house.AddGoodsResponse, error) {
	// todo: add your logic here and delete this line

	goods := mysql.HouseGoods{
		GoodsImg:    in.GoodsImg,
		GoodsAuthor: in.GoodsAuthor,
		GoodsArea:   in.GoodsArea,
		GoodsPrice:  float64(in.GoodsPrice),
		GoodsStatus: int(in.GoodsStatus),
	}
	mysql.DB.Create(&goods)

	return &house.AddGoodsResponse{
		Id: int64(goods.ID),
	}, nil
}
